import scanpy as sc

from pyfeasc.utils.mca import run_mca


# 参数配置
class Config:
	def __init__(self, path, nmcs, meta):
		self.path = path
		self.nmcs = nmcs
		self.meta = meta


# 使用方法
if __name__ == '__main__':
	# config 配置
	config = Config(
			path="../../data/input/anndata/GSE96583.h5ad",
			nmcs=16,
			meta=False
	)
	print("loading data...")
	adata = sc.read_h5ad(config.path)
	adata.var_names_make_unique()
	
	# 过滤掉低质量的基因和低表达的细胞
	print("filtering data...")
	sc.pp.filter_genes(adata, min_cells=3)
	sc.pp.filter_cells(adata, min_genes=200)
	sc.pp.highly_variable_genes(adata, n_top_genes=3000, flavor="cell_ranger")
	adata = adata[:, adata.var.highly_variable]
	
	# 归一化（不能使用 sc.pp.scale）
	sc.pp.normalize_total(adata, target_sum=1e4)
	sc.pp.log1p(adata)
	
	# 降维
	cell_embedding, gene_loading, stdev = run_mca(adata, config.nmcs)
	print()
	
	print("cell_embedding:", cell_embedding.shape)
	print("cell_embedding:", cell_embedding[0:5])
	
	print("gene_loading:", gene_loading.shape)
	print("gene_loading:", gene_loading[0:5])
	
	print("stdev:", stdev.shape)
	print("stdev:", stdev[0:5])
